//
//  HistoryMatchDetailViewController.swift
//  FootballDataRecord
//
//  Created by Xx Jiang on 2020/1/10.
//  Copyright © 2020 Xx Jiang. All rights reserved.
//

import UIKit

class HistoryMatchDetailViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    @IBOutlet weak var topTableView: UITableView! //放比分 和队伍
    @IBOutlet weak var tableView: UITableView! // 方详细数据
    var matchModel:MatchModel!
    
    let typeArr = ["射门","射正","越位","角球","犯规","黄牌","红牌"]
    override func viewDidLoad() {
        super.viewDidLoad()
        setUI()
    }
    override func viewWillAppear(_ animated: Bool) {
        matchModel = (self.parent as!HistoryMatchDetailHomeViewController).matchModel
    }
    func setUI(){
        topTableView.tag = 0
        tableView.tag = 1
        self.topTableView.delegate = self
        self.topTableView.dataSource = self
        self.topTableView.isScrollEnabled = false
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.tableView.register(UINib.init(nibName: "JGJHistoryMatchDetailTableViewCell", bundle: nil), forCellReuseIdentifier: "JGJHistoryMatchDetailTableViewCell")
        self.topTableView.register(UINib.init(nibName: "HistoryMatchTableViewCell", bundle: nil), forCellReuseIdentifier: "HistoryMatchTableViewCell")
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if tableView.tag == 0 {
            return 1
        }
        return 7
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if tableView.tag == 0 {
             let cell = tableView.dequeueReusableCell(withIdentifier: "HistoryMatchTableViewCell") as! HistoryMatchTableViewCell
            cell.selectionStyle = .none
            if matchModel != nil{
            cell.setcell(model: matchModel)
            }
            return cell
        }
        let cell = tableView.dequeueReusableCell(withIdentifier: "JGJHistoryMatchDetailTableViewCell") as! JGJHistoryMatchDetailTableViewCell
        cell.selectionStyle = .none
        
        let teamAmodel = TeamModel.getTeamModelWithTeamID(teamId: matchModel.matchTeamA!)
        let teamBmodel = TeamModel.getTeamModelWithTeamID(teamId: matchModel.matchTeamB!)
        let teamAData = teamAmodel.matchInfo
        let teamBData = teamBmodel.matchInfo
        
        cell.setCell(teamADataModel: teamAData!, teamBDataModel: teamBData!, valueType: typeArr[indexPath.row])
        return cell
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if tableView.tag == 0 {
            return 130.0
        }else{
            return 64.0
        }
    }
}
